<?php
session_start();
    
    // Created By : Julian Ponce
    // B.S. Computer Science - De La Salle Canlubang
    // December 5, 2011
    // IN PARAMETERS : stepId
    // 
    // This AJAX Request gets all stepId information.

    include('../includes/siteConfig.php');
    // CONNECT TO DATABASE
    $connect = mysql_connect($hostName,$rootName,$dBasePassword) or die ('Unable to connect!');
    mysql_select_db($dBaseName) or die ('Unable to select database!');
    
    // PASSED VARIABLES VIA POST
    $stepId = $_POST['stepId'];
    
    // GET STEP ID INFORMATION
    $query = 
        "
            SELECT *
            FROM RouteStep
            WHERE stepId = '$stepId'
        ";
    
    $result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error());
     
    $row = mysql_fetch_array($result);
    
    // SAVES RESULT
    $subRouteIdTemp = $row['subRouteId'];
    
    $jsondata['stepNumber'] = $row['stepNumber'];
    $jsondata['role'] = $row['role'];
    $jsondata['canBeCancelled'] = $row['canBeCancelled'];
    $jsondata['subRouteId'] = $row['subRouteId'];
    $jsondata['userActivity'] = $row['userActivity'];
    $jsondata['category'] = $row['category'];
    
    // GET SUB ROUTE NAME
    // CHECK IF SUB ROUTE ID IS NULL > MAKE subRouteName == "NULL"
    if (is_null($subRouteIdTemp)) {
        $jsondata['subRouteName'] = "NULL";
    }

    // ELSE, GET SUB ROUTE NAME
    else {
        $querySubRouteName = 
            "
                SELECT *
                FROM SubRoute
                WHERE subRouteId = '$subRouteIdTemp'
            ";
        $resultSubRouteName = mysql_query($querySubRouteName) or die ('Error in query: $queryDocumentSetupId. ' . mysql_error());

        $rowRouteName = mysql_fetch_array($resultSubRouteName);
        $jsondata['subRouteName'] = $rowRouteName['subRouteName'];
    }

    echo json_encode($jsondata);
    mysql_free_result($result);
    mysql_close($connect);
    
   
?>
